//远程接口
interface IPrinter {
  print(str: string): void;
}
//本地实现
class ColorPrinter implements IPrinter {
  constructor() {}
  print(str: string): void {
    console.log('打印彩色文字' + str);
  }
}
//远程接口 指定了IPrinter的组合关系
interface IComputer {
  inject(p: IPrinter): void;
}
class Computer implements IComputer {
  private _p!: IPrinter;
  constructor() {}

  public get p(): IPrinter {
    return this._p;
  }

  public set p(v: IPrinter) {
    this._p = v;
  }

  inject(p: IPrinter): void {
    this._p = p;
  }
}
class Program2 {
  constructor() {}
  //代码在本地
  main() {
    let p: IPrinter = new ColorPrinter();
    let pc: Computer = new Computer();
    //远程api
    this.run(pc, p);
  }
  //代码在远程
  run(pc: Computer, p: IPrinter) {
    pc.inject(p);
    pc.p.print('测试页');
  }
}
let p2 = new Program2();
p2.main();
